from pydantic import BaseModel, ConfigDict
from typing import Union
from enum import IntEnum


class Uds_ResponseStatus_Type(IntEnum):
    ZCAN_UDS_ERROR_OK = 0    # 没错误
    ZCAN_UDS_ERROR_TIMEOUT = 1    # 响应超时
    ZCAN_UDS_ERROR_TRANSPORT = 2    # 发送数据失败
    ZCAN_UDS_ERROR_CANCEL = 3    # 取消请求
    ZCAN_UDS_ERROR_SUPPRESS_RESPONSE = 4    # 抑制响应
    ZCAN_UDS_ERROR_BUSY = 5    # 忙碌中
    ZCAN_UDS_ERROR_REQ_PARAM = 6    # 请求参数错误
    ZCAN_UDS_ERROR_OTHTER = 100  # Other


class Uds_Request_Type(BaseModel):
    req_src_addr: int
    req_dst_addr: int
    req_sid: int
    req_param_len: int
    req_data_1: list[int] = []


class Uds_ResponseType_Type(IntEnum):
    NEGATIVE = 0
    POSITIVE = 1


class Uds_Positive_Data_Type(BaseModel):
    # DOC 此处配置允许any
    model_config = ConfigDict(arbitrary_types_allowed=True)
    sid: int
    param: list[int]
    param_len: any


class Uds_Negative_Data_Type(BaseModel):
    neg_code: int
    sid: int
    error_code: int


class Uds_Response_Type(BaseModel):
    model_config = ConfigDict(arbitrary_types_allowed=True)
    status: Uds_ResponseStatus_Type
    type: Uds_ResponseType_Type = None
    response: Union[Uds_Positive_Data_Type, Uds_Negative_Data_Type] = None
    reserved: any = None


class CanMsg_std_type(BaseModel):
    id: int
    id_str: str
    data_list: list[int]
    data_list_str: list[str]
    data_str: str
